/**
 * 维修记录详情对话框（可用于添加和修改对话框）
 */
var modifyInfoDlg = {
    data: {
        modifyId: "",
        modifyNote: "",
        modifyDate: ""
    }
};
var modify = {
    layerIndex: -1,
    condition: {
        modifyNote: "",
        modifyDate: ""
    }
};

/**
 * 表单验证
 * @returns {*}
 */
modifyInfoDlg.validateForm = function () {
    return true;
};
modifyInfoDlg.close = function () {
    parent.layer.close(window.parent.modify.layerIndex);
};


/**
 * 放入和获取id选择器的val
 * @type {{setVal: toVal.setVal, getVal: (function(*): (*|void|jQuery))}}
 */
var toParentVal = {
    setVal: function (data , name) {
        laydate.render({
            elem: '#' + name
        });
        $("#"+name , window.parent.document).val(data);
    },
    getVal: function (name) {
        return $("#"+ name , window.parent.document).val();
    }
};



/**
 * 点击维修记录按钮
 */
modify.openModifyCar = function () {
    this.layerIndex = layer.open({
        type: 2,
        title: '修改维修记录',
        area: ['500px', '300px'],
        fix: false,
        maxmin: true,
        content: Feng.ctxPath + '/modify/modify_edit?modifyId='+toParentVal.getVal("moId")
    });
};

/**
 * 提交维修记录详情
 */
modifyInfoDlg.addSubmit = function () {
    var ajax = new $ax(Feng.ctxPath + "/modify/edit", function (data) {
        window.parent.Feng.success("添加成功!");
        toParentVal.setVal(data,"moId");
        modifyInfoDlg.close();
    }, function (data) {
        window.parent.Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    this.data.modifyDate = Feng.getLaydate();
    ajax.set(this.data);
    ajax.start();
};


$(function () {
    //注意！vue的model绑定和layui有冲突！
    Feng.initLaydate(modifyInfoDlg.data.modifyDate);
    modifyInfoDlg.app = new Vue({
        el: '#modifyForm',
        data: modifyInfoDlg.data,
        methods: {
            submitForm: function (e) {
                e.preventDefault();
            },
            ensure: function () {
                var result = modifyInfoDlg.validateForm();
                if (result === true) {
                    modifyInfoDlg.addSubmit();
                } else {
                    Feng.alert(result);
                }
            },
            close: function () {
                modifyInfoDlg.close();
            }
        }
    });
    //注意！vue的model绑定和layui有冲突！
    Feng.initLaydate(modifyInfoDlg.data.modifyDate);
});



$(function () {
    //获取车辆信息
    var ajax = new $ax(Feng.ctxPath + "/modify/getModifyInfo?modifyId=" + toParentVal.getVal("moId"));
    var result = ajax.start();
    modifyInfoDlg.data = result.data;
    modifyInfoDlg.app = new Vue({
        el: '#modifyForm',
        data: modifyInfoDlg.data,
        methods: {
            submitForm: function (e) {
                e.preventDefault();
            },
            ensure: function () {
                var result = modifyInfoDlg.validateForm();
                if (result === true) {

                } else {
                    Feng.alert(result);
                }
            }
        }
    });
});


























